package com.itheima.mStringTest;

import java.util.Scanner;

/*
      实现用户注册,登录功能
 */
public class WorkStringTest01 {
    public static void main(String[] args) {
        //1.程序中使用一个长度为3的对象数组,存储用户的登录名和密码:
        //注册时要判断数组是否已满,是则禁止注册
        String[][] information = new String[4][3];
        //循环为用户列出列表:
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int op;
        lo:
        while (true) {
            while (true) {
                System.out.println("请输入1-3进行下列操作:");
                System.out.println("1.注册");
                System.out.println("2.登录");
                System.out.println("3.退出");
                op = sc.nextInt();
                if (op == 1 || op == 2 || op == 3) {
                    break;
                } else {
                    System.out.println("输入有误请重新输入!");
                }
            }
            switch (op) {
                case 1:
                    if (count < 3) {
                        registe(information, count);
                        count++;
                    } else {
                        System.out.println("已超出输入上限!");
                    }
                    break;
                case 2:
                    login(information, count);
                    break;
                case 3:
                    System.out.println("感谢您的使用!");
                    break lo;
            }
        }
    }

    public static void registe(String[][] information, int count) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名:");
        information[0][count] = sc.nextLine();
        System.out.println("请输入登陆密码:");
        information[1][count] = sc.nextLine();
        System.out.println("请输入生日日期:");
        information[2][count] = sc.nextLine();
        System.out.println("请输入爱好:");
        information[3][count] = sc.nextLine();
        System.out.println("录入完成!");
    }

    public static void login(String[][] information, int count) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String useName = sc.nextLine();
        System.out.println("请输入登录密码:");
        String passWord = sc.nextLine();
        for (int i = 0; i < 3; i++) {
            if (useName.equals(information[0][i]) && passWord.equals(information[1][i])) {
                System.out.println("用户名:" + information[0][i] + " 密码:" + information[1][i] + " 生日日期:" + information[2][i] + " 爱好:" + information[3][i]);
                return;
            }
        }
        System.out.println("用户名或密码错误!");
    }
}

